# Author: Damian 'Rush' Kaczmarek
# License: MIT

package Zal;
use base Module;
use strict;

use Socket;

my $lastzal;

sub on_public
{
	my $text = $_[1];

	my $time = time();

	if (($text =~ /^!zal (\d+)/ || $text =~ /^!żal (\d+)/) && $time - $lastzal > 1) {
	

# create the socket, connect to the port
socket(SOCKET ,PF_INET,SOCK_STREAM,getprotobyname('tcp'))
    or die "Can't create a socket $!\n";

my $internet_addr = inet_aton("eti.dragoart.info")
    or die "Couldn't convert \"eti.drago.art.info\" into an Internet address: $!\n";

	my $paddr = sockaddr_in(80, $internet_addr);

connect( SOCKET, $paddr)
    or die "Can't connect to port 80! \n";

my $post_nr = $1;
my $zal_line = "mode=add_point&post_id=$post_nr&user_id=-1&username=arczia&poster_id=195&typ=zal";


print "Sending zal ...";
print SOCKET "POST /points_system.php HTTP/1.1
Host: eti.dragoart.info
User-Agent: Mozilla/5.0
Content-Type: application/x-www-form-urlencoded;
Content-Length: ".length($zal_line)."
Connection: Keep-Alive

$zal_line
";

close SOCKET;

		Core::send_msg("Dodano żal.");
		$lastzal = $time;
	}
}
1;
